import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { AccountEntity } from 'src/account/entities/account.entity';
import { DeleteResult, Repository, UpdateResult } from 'typeorm';

@Injectable()
export class AccountService {
  constructor (
    @InjectRepository(AccountEntity)
    private readonly accountRepository: Repository < AccountEntity >,
  ) { }

  async createAccount(data: any):Promise<any> {
    const result = this.accountRepository.create(data);
    return await this.accountRepository.save(result);
  }

  async deleteAccountById(id: number): Promise<DeleteResult> {
    return await this.accountRepository.softDelete(id);
  }

  async modifyAccountById(id: number, data: any):Promise<UpdateResult> {
    return await this.accountRepository.update(id, data);
  }

  async accountList():Promise<any> {
    return await this.accountRepository.find();
  }
}

